package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysVarity;
import com.ruoyi.system.service.ISysVarityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 品种Controller
 * 
 * @author ruoyi
 * @date 2022-07-20
 */
@RestController
@RequestMapping("/system/varity")
public class SysVarityController extends BaseController
{
    @Autowired
    private ISysVarityService sysVarityService;

    /**
     * 查询品种列表
     */
    @PreAuthorize("@ss.hasPermi('system:varity:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysVarity sysVarity)
    {
        startPage();
        List<SysVarity> list = sysVarityService.selectSysVarityList(sysVarity);
        return getDataTable(list);
    }

    /**
     * 导出品种列表
     */
    @PreAuthorize("@ss.hasPermi('system:varity:export')")
    @Log(title = "品种", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysVarity sysVarity)
    {
        List<SysVarity> list = sysVarityService.selectSysVarityList(sysVarity);
        ExcelUtil<SysVarity> util = new ExcelUtil<SysVarity>(SysVarity.class);
        util.exportExcel(response, list, "品种数据");
    }

    /**
     * 获取品种详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:varity:query')")
    @GetMapping(value = "/{varityId}")
    public AjaxResult getInfo(@PathVariable("varityId") Long varityId)
    {
        return AjaxResult.success(sysVarityService.selectSysVarityByVarityId(varityId));
    }

    /**
     * 新增品种
     */
    @PreAuthorize("@ss.hasPermi('system:varity:add')")
    @Log(title = "品种", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysVarity sysVarity)
    {
        return toAjax(sysVarityService.insertSysVarity(sysVarity));
    }

    /**
     * 修改品种
     */
    @PreAuthorize("@ss.hasPermi('system:varity:edit')")
    @Log(title = "品种", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysVarity sysVarity)
    {
        return toAjax(sysVarityService.updateSysVarity(sysVarity));
    }

    /**
     * 删除品种
     */
    @PreAuthorize("@ss.hasPermi('system:varity:remove')")
    @Log(title = "品种", businessType = BusinessType.DELETE)
	@DeleteMapping("/{varityIds}")
    public AjaxResult remove(@PathVariable Long[] varityIds)
    {
        return toAjax(sysVarityService.deleteSysVarityByVarityIds(varityIds));
    }
}
